import type {
  everyData,
  DataDetail,
  PromisType,
  LoginParams,
  LoginResponse,
  SignupParams,
  SignupResponse,
  MedicalResponse,
} from '@/types/home'
import type * as TYPES from '@/types/home'
import { request } from '@/utils/request'
// 首页请求新闻列表
export const getHomeNewsData = (): Promise<PromisType> => {
  return request({
    url: '/news/list?page=1&pagenum=4',
    method: 'GET',
  })
}
// 获取新闻详情
export const getNewsDetailData = (id: string): Promise<TYPES.NewsDetail> => {
  return request({
    url: `/news/detail`,
    method: 'POST',
    data: {
      nid: id,
    },
  })
}

// 封装登录请求
// Promise代表的是一个还没有完成但即将会完成的操作
// 这里代表的是 Promise 最终会返回一个 LoginResponse 类型的结果
export const loginApi = (data: LoginParams): Promise<LoginResponse> => {
  return request({
    url: '/user/login',
    method: 'POST',
    data,
  })
}
//封装注册请求
export const SignupApi = (data: SignupParams): Promise<SignupResponse> => {
  return request({
    url: '/user/register',
    method: 'POST',
    data,
  })
}
// 获取用户数据
export const getUserListData = (): Promise<PromisType> => {
  return request({
    url: '/user/list',
    method: 'GET',
  })
}
// 获取在线问诊数据

// 获取用药提醒列表
export const getYytxListData = (uid: string): Promise<TYPES.YytxListData> => {
  return request({
    url: `/reminder/list?uid=${uid}`,
    method: 'GET',
  })
}

// 药品查询页面请求药品列表
export const getMedicalListData = (): Promise<MedicalResponse> => {
  return request({
    url: '/search/drugs/list?page=1&pagenum=10',
    method: 'GET',
  })
}

// 新增用药提醒
export const addYytxData = (data: TYPES.AddYytxData): Promise<TYPES.AddYytxParams> => {
  return request({
    url: '/reminder/add',
    method: 'POST',
    data,
  })
}
// 删除用药提醒
export const deleteYytxData = (rid: string): Promise<TYPES.AddYytxParams> => {
  return request({
    url: `/reminder/del`,
    method: 'POST',
    data: {
      rid: rid,
    },
  })
}
// 获取预约挂号医院数据
export const getYyghDoctorData = (): Promise<any> => {
  return request({
    url: '/hospital/limit',
    method: 'POST',
    data: {
      page: 1,
      pagenum: 10,
    },
  })
}
// 医院科室查询
export const getYyghDeptData = (hid: number): Promise<any> => {
  return request({
    url: `/hospital/subject`,
    method: 'POST',
    data: {
      hid: hid,
    },
  })
}
// 通过科室和医院查医生
export const getYyghDoctorByDept = (did: number, hid: number): Promise<any> => {
  return request({
    url: `/doctor/byHidAndDid`,
    method: 'POST',
    data: {
      did: did,
      hid: hid,
    },
  })
}
// 新增预约挂号
export const addYyghData = (data: any): Promise<any> => {
  return request({
    url: '/register/add',
    method: 'POST',
    data,
  })
}
// 查询药品列表
export const getYpListData = (): Promise<any> => {
  return request({
    url: '/bible/query',
    method: 'GET',
  })
}
// 分类下疾病列表
export const getJbListData = (fid: number): Promise<any> => {
  return request({
    url: '/bible/queryFid',
    method: 'POST',
    data: {
      id: fid,
    },
  })
}
// 获取所有医生信息
export const getAllDoctorListData = (): Promise<any> => {
  return request({
    url: '/doctor/list?page=1&pagenum=20',
    method: 'GET',
  })
}
// 模糊搜索医生
export const searchDoctorData = (name: string): Promise<any> => {
  return request({
    url: `/doctor/search?key=${name}`,
    method: 'GET',
  })
}
// 获取好医生
export const getYyghGoodDoctorData = (): Promise<any> => {
  return request({
    url: '/doctor/recommend',
    method: 'GET',
  })
}